﻿using System;
namespace Calculator.Xroad.Eu.Headers {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="GetHistoryOutputHeader", Namespace="http://calculator.x-road.eu", Target=typeof(GetHistoryOutputHeader))]
    public class GetHistoryOutputHeaderSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected GetHistoryOutputHeader clazz;
        
        public GetHistoryOutputHeaderSerializer(GetHistoryOutputHeader clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/xroad.xsd"), "client", "http://x-road.eu/xsd/xroad.xsd");
            if (clazz.Client!=null) {
                global::Xtee.Core.SerializationMetadata metaClient = this.GetMetaData(clazz.Client);
                if (ShouldWriteTypeAttribute(typeof(global::Xroad.Eu.Xsd.Identifiers.XRoadClientIdentifierType), clazz.Client.GetType())) {
                    Writer.WriteTypeAttribute(metaClient.TypeQualifiedName.Namespace, metaClient.TypeQualifiedName.Name);
                }
                var clientSerializer = metaClient.NewSerializer(clazz.Client);
                clientSerializer.WriteXmlAttributes(Writer);
                clientSerializer.WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Client");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/xroad.xsd"), "service", "http://x-road.eu/xsd/xroad.xsd");
            if (clazz.Service!=null) {
                global::Xtee.Core.SerializationMetadata metaService = this.GetMetaData(clazz.Service);
                if (ShouldWriteTypeAttribute(typeof(global::Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType), clazz.Service.GetType())) {
                    Writer.WriteTypeAttribute(metaService.TypeQualifiedName.Namespace, metaService.TypeQualifiedName.Name);
                }
                var serviceSerializer = metaService.NewSerializer(clazz.Service);
                serviceSerializer.WriteXmlAttributes(Writer);
                serviceSerializer.WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Service");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/xroad.xsd"), "id", "http://x-road.eu/xsd/xroad.xsd");
            if (clazz.Id!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Id))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Id");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/xroad.xsd"), "userId", "http://x-road.eu/xsd/xroad.xsd");
            if (clazz.UserId!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.UserId))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : UserId");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/xroad.xsd"), "issue", "http://x-road.eu/xsd/xroad.xsd");
            if (clazz.Issue!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Issue))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Issue");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/xroad.xsd"), "protocolVersion", "http://x-road.eu/xsd/xroad.xsd");
            if (clazz.ProtocolVersion!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ProtocolVersion))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ProtocolVersion");
            }
            Writer.WriteEndElement();
            if (clazz.RequestHash!=null) {
                Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/xroad.xsd"), "requestHash", "http://x-road.eu/xsd/xroad.xsd");
                Writer.WriteString(clazz.RequestHash.ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "client")) {
                goto client;
            }
            else {
                if ((Reader.LocalName == "service")) {
                    goto service;
                }
                else {
                    if ((Reader.LocalName == "id")) {
                        goto id;
                    }
                    else {
                        if ((Reader.LocalName == "userId")) {
                            goto userId;
                        }
                        else {
                            if ((Reader.LocalName == "issue")) {
                                goto issue;
                            }
                            else {
                                if ((Reader.LocalName == "protocolVersion")) {
                                    goto protocolVersion;
                                }
                                else {
                                    if ((Reader.LocalName == "requestHash")) {
                                        goto requestHash;
                                    }
                                    else {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        client:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>client");
            }
            global::Xtee.Core.SerializationMetadata metaClient = this.GetMetaData<global::Xroad.Eu.Xsd.Identifiers.XRoadClientIdentifierType>(Reader, "XRoadClientIdentifierType", "http://x-road.eu/xsd/identifiers");
            clazz.Client = metaClient.NewEntity<global::Xroad.Eu.Xsd.Identifiers.XRoadClientIdentifierType>();
            if ((Reader.IsEmptyElement == false)) {
                var clientSerializer = metaClient.NewSerializer(clazz.Client);
                clientSerializer.ReadXmlAttributes(Reader);
                Reader.ReadStartElement("client", "http://x-road.eu/xsd/xroad.xsd");
                clientSerializer.ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        service:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>service");
            }
            global::Xtee.Core.SerializationMetadata metaService = this.GetMetaData<global::Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType>(Reader, "XRoadServiceIdentifierType", "http://x-road.eu/xsd/identifiers");
            clazz.Service = metaService.NewEntity<global::Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType>();
            if ((Reader.IsEmptyElement == false)) {
                var serviceSerializer = metaService.NewSerializer(clazz.Service);
                serviceSerializer.ReadXmlAttributes(Reader);
                Reader.ReadStartElement("service", "http://x-road.eu/xsd/xroad.xsd");
                serviceSerializer.ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        id:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>id");
            }
            clazz.Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("id", "http://x-road.eu/xsd/xroad.xsd")).Value;
            goto START;
        userId:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>userId");
            }
            clazz.UserId = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("userId", "http://x-road.eu/xsd/xroad.xsd")).Value;
            goto START;
        issue:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>issue");
            }
            clazz.Issue = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("issue", "http://x-road.eu/xsd/xroad.xsd")).Value;
            goto START;
        protocolVersion:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>protocolVersion");
            }
            clazz.ProtocolVersion = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("protocolVersion", "http://x-road.eu/xsd/xroad.xsd")).Value;
            goto START;
        requestHash:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>requestHash");
            }
            clazz.RequestHash = new GetHistoryOutputHeader.RequestHashType(Reader.ReadElementString("requestHash", "http://x-road.eu/xsd/xroad.xsd"));
            goto START;
        }
    }
}
